	<!DOCTYPE html>
	<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>新疆汽配网后台</title>
		<link rel="stylesheet" href="/Public/layui/css/layui.css">
		<style type="text/css">
		   
		</style>
	</head>
	<body>
		 <!--添加商品表单-->
	  <div id="add_car" style=" padding:20px;">
			<form class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">汽车名称</label>
					<div class="layui-input-block">
						<input type="text" name="name" id="name" lay-verify="required" placeholder="请输入名称" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">首字母</label>
					<div class="layui-input-block">
						<input type="text" name="pinyin" id="pinyin" lay-verify="required" placeholder="请输入首字母" class="layui-input" lay-verify="number">
					</div>
				</div>


				<div class="layui-upload">
				  <label class="layui-form-label">汽车图片</label>
				  <button type="button" class="layui-btn" id="test1">上传图片</button>
				  <div class="layui-upload-list" style="padding-left: 110px;">
				    <img class="layui-upload-img" id="demo1" style="width: 105px;height: 105px;">
				  </div>
				</div> 
						
				<div id="upload_add_user_div" style="color:#bcbcbc; float:left;height:40px;line-height:40px;margin-left:120px;"></div>
				<div class="layui-form-item" style="margin-top:20px;">
					<div class="layui-input-block">
						<button  class="layui-btn" class="layui-btn" lay-submit lay-filter="add_car">保存</button>
					</div>
				</div>
			</form>
		</div>
		<script src="/Public/layui/layui.all.js"></script>
		<script type="text/javascript">
			var head_ico_path=""; //图片路径
			 //图片上传
			 upload.render({
	    		elem: '#test1',
	    		url: '/Admin/CarType/car_ico',
	    		before: function(obj){
	      			//预读本地文件示例，不支持ie8
		        obj.preview(function(index, file, result){
		       		 $('#demo1').attr('src', result); //图片链接（base64）
		      		});
		    	},
		    	done: function(res){
		    		head_ico_path = res.src;
		    		$('#upload_add_user_div').html("已上传");
	    		}
			});

		   //用户添加
			form.on('submit(add_car)', function(data){
				data.field.logo = head_ico_path;       
			    console.log(data.field);
			      var param=data.field;
		    		 ajax('/Admin/CarType/add_car',param,function(res){
					 layer.msg(res.msg);
					 window.location.href="/Admin/CarType/index"
					})
			   	return false; //阻止表单跳转
			});
		</script>
	</body>
	</html>